package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jiyun.model.pojo.Address;
import com.jiyun.service.AddressService;
import com.jiyun.mapper.AddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【address】的数据库操作Service实现
* @createDate 2025-01-18 09:34:13
*/
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address>
    implements AddressService{

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public List<Address> showlist(Integer id) {
        QueryWrapper<Address> qw = new QueryWrapper<>();
        qw.eq("id",id);
        return addressMapper.selectList(qw);
    }

    @Override
    public void updateDefault(Integer id, Long addressId) {
        addressMapper.updateDefault(id,addressId);
        addressMapper.updateDefault1(id,addressId);
    }

    @Override
    public Address getDefault(Integer id) {
        return addressMapper.selectOne(new QueryWrapper<Address>()
                .eq("id", id)
                .eq("is_default", true));
    }

    @Override
    public void delete(Long id) {
        addressMapper.del(id);
    }

    @Override
    public void deleteByUserId(Integer id) {
        addressMapper.deleteByUserId(id);
    }


}




